|
|
|
|
|
|
|
The Point function returns the RGB color specification of a point in a form or picture box. The following code shows a MouseDown event handling procedure for a picture box named picColors. When you click the mouse over the picture box, this routine uses the Point function to display the hexadecimal color value of the pixel pointed to by the mouse. |
|
|
|
 |
|
|
|
|
Private Sub picColors_MouseDown(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
MsgBox Hex$(Picture1.Point(X, Y))
End Sub |
|
|
|
|
|
|
|
|
The PSet routine sets the color value of a pixel. For example, the following code turns the pixel clicked red in the picture box picColors. |
|
|
|
 |
|
|
|
|
Private Sub picColors_MouseDown(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
picColors.PSet (X, Y), vbRed
End Sub |
|
|
|
|
|
|
|
|
The Point and PSet routines let you examine and set the colors of every pixel in an image one at a time. They are very simple, but they are also quite slow. The GetBitmapBits and SetBitmapBits functions described in Chapter 3, Advanced Color, are much faster. |
|
|
|
|
|
|
|
|
Example program SetPix demonstrates three different techniques for setting every pixel in three picture boxes containing 150 * 150 = 22,500 pixels. It sets the pixels in its left picture box using PSet. |
|
|
|
|
|
|
|
|
SetPix sets its middle picture box's pixels using the SetBitmapPixels subroutine described in Chapter 3. That routine copies color values stored in an RGBTriplet array into the picture box. For more information on this routine, see Chapter 3. |
|
|
|
|
|
|
|
|
To fill its right picture box, the SetPix program fills an array of bytes with color values. It then calls the SetBitmapBits API function directly. This is the same operation performed by the SetBitmapPixels subroutine. Invoking SetBitmapBits directly is more complex, but it provides somewhat better performance. |
|
|
|
|
|
|
|
|
Program SetPix assumes it is running on a 24-bit color system. This assumption makes using the SetBitmapPixels and SetBitmapBits functions easier. |
|
|
|
|
|
|
|
|
In one test, a 133MHz Pentium processor took roughly 8.26 seconds to fill its left picture box using PSet. It took approximately 0.61 seconds to fill the middle picture box using SetBitmapPixels, and it needed only 0.35 seconds to fill its right picture box using SetBitmapBits. These three methods give you a tradeoff between complexity and speed. SetBitmapPixels takes less than 1/10th as long as the PSet method, but it is more complicated. SetBitmapBits takes slightly more than half as long as SetBitmapPixels, but it is even more complicated. |
|
|
|
|
|